{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('/admin/game')}">游戏管理</a></li>
            <li class=""><a href="{:url('/admin/game/add')}">添加游戏</a></li>
            <li class="layui-this">编辑游戏</li>
        </ul>
        <div class="layui-tab-content">
            <form class="layui-form" action="{:url('/admin/game/update')}" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">游戏名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="{$game.name}" required  lay-verify="required" placeholder="游戏名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CP名称</label>
                    <div class="layui-input-block">
                        <select name="gchannel" lay-search>
                            <option value="0">{$game['gchannel']}</option>
                            {foreach name=":get_cp_list()" item="vo"}
                                <option value="{$vo.id}"{if condition="$game['gchannel']==$vo['id']"}selected{/if} >{$vo.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">登录地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="api_login_url" value="{$game.api_login_url}" required  lay-verify="required" placeholder="登录地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">支付通知地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="api_pay_url" value="{$game.api_pay_url}" required  lay-verify="required" placeholder="支付通知地址" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">通道费（%）</label>
                    <div class="layui-input-block">
                        <input type="text" name="cfencheng" value="{$game.cfencheng}" required  lay-verify="required" placeholder="通道费" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">CP分成（%）</label>
                    <div class="layui-input-block">
                        <input type="text" name="gfencheng" value="{$game.gfencheng}" required  lay-verify="required" placeholder="CP分成" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">游戏背景</label>
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="uploadBgimg">上传图片</button>
                            <div class="layui-upload-list">
                                {if condition="$game.Bgimg"}
                                    <img class="layui-upload-img" id="iconPreview" style="max-width: 100px;" src="{$game['Bgimg']}">
                                {else/}
                                    <img class="layui-upload-img" id="iconPreview" style="max-width: 100px; display: none;">
                                {/if}
                                <p id="uploadText"></p>
                            </div>
                            <input type="hidden" name="Bgimg" id="iconPath">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="gstatus" value="0" title="未上线/禁用"{if condition="$game.gstatus==0"} checked="checked"{/if}>
                        <input type="radio" name="gstatus" value="2" title="测试中"{if condition="$game.gstatus==2"} checked="checked"{/if}>
                        <input type="radio" name="gstatus" value="1" title="上线"{if condition="$game.gstatus==1"} checked="checked"{/if}>
                    </div>
                </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
				  <input type="hidden" name="id" value="{$game.id}">
                  <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
              </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    //自定义验证规则
    ;!function(){
        var layer = layui.layer
                ,form = layui.form
                ,upload = layui.upload;

        //上传图片
        upload.render({
            elem: '#uploadBgimg',
            url: '{:url("/admin/uploadImg")}', //改成你的上传接口
            accept: 'images',
            acceptMime: 'image/*',
            done: function(res){
                console.log(res);
                if(res.error == 0){ //上传成功
                    $('#iconPreview').attr('src', res.url).show();
                    $('#iconPath').val(res.url);
                    $('#uploadText').html('<span style="color: #4cae4c;">上传成功</span>');
                } else {
                    $('#uploadText').html('<span style="color: #ff5722;">上传失败：'+ res.msg +'</span>');
                }
            },
            error: function(){
                $('#uploadText').html('<span style="color: #ff5722;">上传失败</span>');
            }
        });

        form.verify({
            title: function(value){
                if(value.length < 2){
                    return '游戏名称至少得2个字符啊';
                }
            }
            ,key: [/([a-fA-F0-9]{32})$/, '密钥必须32位MD5']
            ,content: function(value){
                layedit.sync(editIndex);
            }
            ,letter: function(value){
                if(value.length > 1 || /[A-Z]/.test(value) == false){
                    return '首字母必须大写且不能超过1个字符';
                }
            }
            ,ename: function(value){
                if(!/[A-Za-z]$/.test(value)){
                    return '请输入英文或拼音且不能包含数字和中文';
                }
            }
        });
    }();
</script>


{/block}